﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace test
{
    class Program
    {
        delegate int intRet();
        static void Main(string[] args)
        {
            DateTime dt = DateTime.Now;
            Console.WriteLine("Parent start");
            Task<int> task1 = new Task<int>(() =>
                                {
                                    Console.WriteLine("Task 1 started");
                                    Thread.Sleep(1000);
                                    Console.WriteLine("Task 1 ended");
                                    return 1;
                                }, TaskCreationOptions.PreferFairness | TaskCreationOptions.AttachedToParent);
            Task<int> task2 = new Task<int>(task2func, TaskCreationOptions.PreferFairness | TaskCreationOptions.AttachedToParent);
                                    
            Console.WriteLine("Starting task 1...");
            task1.Start();
            Console.WriteLine("Task 1 ended. Returned: " + task1.Result);

            Console.WriteLine("Starting task 2...");
            task2.Start();
            Console.WriteLine("Task 2 ended. Returned: " + task2.Result);

            Console.ReadLine();
        }

        private static int task2func()
        {
            Console.WriteLine("Task 2 started");
            Thread.Sleep(1000);
            Console.WriteLine("Task 2 ended");
            return 2;
        }
    }
}
